home *** CD-ROM | disk | FTP | other *** search
/ Biodiversity of Illinois 2: Woodland Habitats / Biodiversity of Illinois 2 - Woodland Habitats.iso / mac / casts / PDFxtraBehaviors.cst / 00004_Script_PDF_Open from field < prev    next >
Text File  |  2006-07-11  |  10KB  |  231 lines

  1. -- Open
  2.  
  3. Property pEvent, pSprite, pMemberName, pPathType, pEnableUpdateFromURL, pUpdateFromURL, pPage, pZoom, pScale, pDisplayMode, pToolbar, pScrollbars, pScrollH, pScrollV, pAlertFlag
  4.  
  5. on doOpen me
  6.   
  7.   -- get the pathname from the text member
  8.   myMember = me.ExtractMemberFromString(pMemberName)[2]
  9.   f = myMember.text
  10.   
  11.   if (f="") then exit
  12.   case pZoom of:
  13.     "Fit Width": set zm = #fitWidth
  14.     "Actual Size": set zm = #actualSize
  15.     "Fit Page": set zm = #fitPage
  16.      "Fit Visible": set zm = #fitVisible
  17.     otherwise: 
  18.       if (pScale<8) or (pScale>1600) then
  19.         alert "Invalid zoom value"
  20.         exit
  21.       else
  22.         set zm = pScale
  23.       end if
  24.   end case
  25.   case pDisplayMode of:
  26.     "Pages Only": set dm = #pagesOnly
  27.     "Bookmarks and Pages": set dm = #bookmarkAndPages
  28.     "Thumbnails and Pages": set dm = #thumbnailAndPages
  29.   end case
  30.   set err = PDF_Open(sprite pSprite, f, [#pathtype: pPathType, #EnableUpdateFromURL: pEnableUpdateFromURL, #UpdateFromURL: pUpdateFromURL, #DisplayOption: #customdisplayoptions, #page:pPage, #zoom:zm, #displayMode:dm, #toolbar:pToolbar, #scrollBars:pScrollbars, #scrollH:pScrollH, #scrollV:pScrollV])
  31.   if PDF_status(sprite pSprite) then alert "PDF Behavior Error"&RETURN&PDF_error(sprite pSprite)
  32. end doOpen
  33.  
  34. on mouseUp me
  35.   if (pEvent = #mouseUp) then doOpen(me)
  36. end mouseUp
  37.  
  38. on mouseDown me
  39.   if (pEvent = #mouseDown) then doOpen(me)
  40. end mouseDown
  41.  
  42. on prepareFrame me
  43.   if (pEvent = #prepareFrame) then doOpen(me)
  44. end prepareFrame
  45.  
  46. on beginsprite me
  47.   if (pEvent = #beginsprite) then doOpen(me)
  48. end beginsprite
  49. -- standard behavior stuff --
  50. on getPropertyDescriptionList me
  51.   set defaultValues = GetDefaultValues (me)
  52.   
  53.   set pdfSpriteList = getProp (defaultValues, #spriteList)
  54.   set defSprite     = getProp (defaultValues, #defaultSprite)
  55.   if (defSprite=0) then 
  56.     if the ticks - pAlertFlag > 10 then
  57.       alert "Please create a sprite of type PDF first."
  58.     end if
  59.     set pAlertFlag = the ticks -- The ticks when the user clicked "OK"
  60.     
  61.     exit
  62.   end if
  63.   
  64.   -- retrieve all members of type text, field or Flashcomponent
  65.   lTextFields = me.GetMembers([#text, #field, #flashcomponent])
  66.   if (lTextFields = []) then
  67.     if the currentSpriteNum then
  68.       alert "You need at least one member of type #field or #text to use this behavior."
  69.     end if
  70.     exit
  71.   end if 
  72.   
  73.   set p_list = [:]
  74.   addprop p_list,#pEvent, [ #comment: "Event", #format:#symbol, #range:[#mouseUp, #mouseDown, #prepareFrame, #beginsprite], #default:#mouseUp]
  75.   addprop p_list,#pSprite, [ #comment: "PDF Sprite is in channel:", #format:#symbol, #range:pdfSpriteList, #default:defSprite]
  76.   if (lTextFields.count = 0) then
  77.     addprop p_list, #pMemberName, [ #comment: "File name is in member:", #format: #string, #default:"<no named fields or text members available>"]
  78.   else  
  79.     addprop p_list, #pMemberName, [ #comment: "File name is in member:", #format:#member, #default:lTextFields[1], #range:lTextFields]
  80.   end if 
  81.   addprop p_list,#pPathType, [ #comment: "Path is:", #format: #symbol, #range: [ "Absolute or URL", "Relative to Movie", "Relative to Playback Engine"],#default: "Absolute or URL" ]
  82.   addprop p_list,#pEnableUpdateFromURL, [ #comment: "Enable update URL:", #format:#boolean, #default:FALSE ]
  83.   addprop p_list,#pUpdateFromURL, [ #comment: "Update URL (if enabled):", #format:#string, #default:"http://" ]
  84.   addprop p_list,#pPage, [ #comment: "Start at page:", #format: #integer, #default:1 ]
  85.   addprop p_list,#pZoom, [ #comment: "Start at zoom:", #format:#symbol, #range:["Fit Width", "Actual Size", "Fit Page", "Fit Visible", "Other (specify below)"], #default:"Fit Width"]
  86.   addprop p_list,#pScale, [ #comment: "Other zoom (8..1600):", #format:#integer, #default:""]
  87.   addprop p_list,#pDisplayMode, [ #comment: "Display mode:", #format:#symbol, #range:["Pages Only", "Bookmarks and Pages", "Thumbnails and Pages"],#default:"Pages Only" ]
  88.   addprop p_list,#pToolbar, [ #comment: "Show Toolbar:", #format:#boolean, #default:TRUE ]
  89.   addprop p_list,#pScrollbars, [ #comment: "Show Scrollbars:", #format:#boolean, #default:TRUE ]
  90.   addprop p_list,#pScrollH, [ #comment: "Scroll H:", #format: #integer, #default:0 ]
  91.   addprop p_list,#pScrollV, [ #comment: "Scroll V:", #format: #integer, #default:0 ]
  92.   return p_list
  93. end
  94.  
  95. on getBehaviorDescription
  96.   tmp ="Link the PDF document, whose name is specified in a Director field, to the designated PDF Xtra sprite. If the designated sprite is already linked to a PDF document, that document is first closed and then the new one opened." & RETURN& "All platforms."
  97.   tmp = tmp &RETURN&RETURN& "--- PARAMETERS --- " &RETURN& " - Event: mouseUp, mouseDown, prepareFrame, or beginSpritePDF"
  98.   tmp = tmp &RETURN& " - Sprite is in channel: which channel contains the PDF Sprite"
  99.   tmp = tmp & RETURN& " - File name is in field: the field cast member that contains the name of the PDF document to open."
  100.   tmp = tmp & RETURN& " - Path is: Absolute or URL, Relative to Movie, Relative to Playback Engine."
  101.   tmp = tmp & RETURN& " - Enable update URL: If this box is checked, there must be a valid URL in the Update URL field."
  102.   tmp = tmp & RETURN& " - Update URL: The URL containing the PDF document to download if the local one is older."
  103.   tmp = tmp & RETURN& " - Start at page: Which page of the document should be displayed on opening."
  104.   tmp = tmp & RETURN& " - Start at zoom: Fit Width, Actual Size, Fit Page, Fit Visible, Other."
  105.   tmp = tmp & RETURN& " - Other zoom (8..1600): A number representing the percentage to scale the document."
  106.   tmp = tmp & RETURN& " - Display mode: Pages Only, Bookmark And Pages, or Thumbnail And Pages"
  107.   tmp = tmp & RETURN& " - Show Toolbar: Display toolbar if checked (to show the toolbar in Director, the PDF document must have been saved in Acrobat, with the toolbar showing); hide the toolbar otherwise."
  108.   tmp = tmp & RETURN& " - Show Scrollbars: Display scrollbars if checked; hide scrollbars otherwise." & RETURN & " - Scroll H: Set the horizontal scroll position to the number of pixels specified."
  109.   tmp = tmp & RETURN& " - Scroll V: Set the vertical scroll position to the number of pixels specified."
  110.   tmp = tmp &RETURN&RETURN& "Free to use and abuse. (c)1999-2005, Integration New Media, Inc." &RETURN& "Thanks to James Newton for his suggestions"  
  111.   return tmp  
  112. end
  113.  
  114. on getBehaviorTooltip
  115.   return "Attached to a button, background object." &RETURN& "Link a PDF document, whose name is specified in a Director field," &RETURN& "to the designated PDF Xtra sprite." &RETURN& "If the sprite is already linked to a PDF document, that document is" &RETURN& "first closed and then the new one opened." & RETURN& "All platforms."
  116. end
  117.  
  118. -- utils --
  119. on GetDefaultValues me
  120.   if the currentSpriteNum then
  121.     set spriteList = GetSpriteList (me #PDF)
  122.     if count (spriteList) then
  123.       set defaultSprite = getAt (spriteList, 1)
  124.     else
  125.       set defaultSprite = 0
  126.     end if
  127.     
  128.     return [#spriteList: spriteList, #defaultSprite: defaultSprite]
  129.     
  130.   else -- the currentSpriteNum = 0
  131.     -- Director is merely recompiling this script: return dummy values
  132.     return [#spriteList: [1], #defaultSprite: 1]
  133.   end if
  134. end 
  135.  
  136.  
  137. on GetSpriteList me, memberType
  138.   -- return list of sprites of type memberType in current frame
  139.   global version
  140.   if (char 1 of version = 6) then
  141.     set maxSprite = 120
  142.   else
  143.     set maxSprite = the lastChannel
  144.   end if
  145.   
  146.   set aList=[]
  147.   
  148.   repeat with i = 1 to maxSprite
  149.     set spriteMember = the member of sprite i
  150.     -- if (string(m) contains "member 0") then next repeat -- unnecessary
  151.     if (the type of spriteMember = memberType) then -- (JN) Line break
  152.       append (aList, i)
  153.     end if
  154.   end repeat
  155.   
  156.   return aList
  157. end GetSpriteList
  158.  
  159.  
  160. on GetMembers me, theMembersTypeNeeded  
  161.   
  162.   lResult = []
  163.   
  164.   lCastLib = the number of castLibs
  165.   
  166.   repeat while lCastLib -- repeat through all linked castlibs
  167.     
  168.     lMemberNum = the number of members of castLib(lCastLib)
  169.     
  170.     repeat while lMemberNum -- repeat through all members of the current castlib
  171.       lMemberType = member(lMemberNum, lCastLib).type
  172.       
  173.       if (theMembersTypeNeeded.getOne(lMemberType) > 0) then -- check if the member's type is contained in theMembersTypeNeeded
  174.         lName = member(lMemberNum, lCastLib).name 
  175.         if (lName <> "") then 
  176.           
  177.           lResult.AddAt(1, lName&&"(member"&&lMemberNum&&"of castlib"&&lCastLib&")") -- Add the member to the list
  178.         end if
  179.       end if
  180.       
  181.       set lMemberNum = lMemberNum - 1 -- check the next member
  182.     end repeat
  183.     
  184.     set lCastLib = lCastLib - 1 -- check the next castlib
  185.   end repeat
  186.   
  187.   return lResult
  188. end GetMembers
  189.  
  190. --
  191. -- Extract name and reference to a member contained in a string
  192. --    in a list [<name>, <(member xxx of castlib yyy)>]
  193. -- the String contains a reference to a member formatted like
  194. --    "<member name> (member xxx of castlib yyy)"
  195. --
  196. on ExtractMemberFromString me, theString
  197.   lResult = ["", VOID]
  198.   
  199.   if (StringP(theString)) then -- check if theString contains a string
  200.     lPos = offset("(member ", theString) -- find the offset of the substring "(member "
  201.     if (lPos > 0) then -- substring found = theString is a valid member reference
  202.       lName= ""
  203.       
  204.       if (lPos > 2) then
  205.         lName = theString.char[1..lPos-2]
  206.         if (lName) = "<no name>" then
  207.           lName = ""
  208.         end if
  209.       end if
  210.       
  211.       lMember = value(theString.char[lPos..theString.chars.count])
  212.       -- check if the member name and member reference are consistent
  213.       if (lMember <> VOID) then
  214.         if (lMember.name <> lName) then -- the user probably moved the cast member, we'll try to find it
  215.           if (lName <> "") then -- the member didn't have a name, so it's useless to look for it
  216.             lMember = member(lName)
  217.           else
  218.             lMember = VOID
  219.           end if
  220.         end if
  221.       end if
  222.       
  223.       lResult = [lName, lMember]
  224.     end if
  225.   end if
  226.   
  227.   return lResult
  228. end ExtractMemberFromString
  229.  
  230.  
  231.